package com.egao.gzh.service;

import com.egao.common.core.damon.utils.HttpsUtils;
import net.sf.json.JSONObject;

/**
 * @author Damon
 * @create 2020-09-02 12:16
 */
public class GzhGetQRcode {

    /**
     * 得到生成二维码需要的ticket
     * @return
     */
    public static String getQRcodeTicket(String param) {
        String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+ GzhToken.getAccessToken();
        //生成临时字符串二维码 expire_seconds 单位秒
        //{"scene_str": "customerId=12;customerName=中盈"}
        String data = "{\"expire_seconds\": 2000, \"action_name\": \"QR_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \""+param+"\"}}}";
        String post = HttpsUtils.post(url, data);
        String ticket = JSONObject.fromObject(post).getString("ticket");
        return ticket;
    }

    public static void main(String[] args) {
        GzhGetQRcode q = new GzhGetQRcode();
        System.out.println(q.getQRcodeTicket("userId=112"));
    }

    public String getQrCode(){
        String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ getQRcodeTicket("user=22");
        return url;
    }
}
